package com.ruoyi.otc.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.otc.domain.Topic;
import com.ruoyi.otc.service.ITopicService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 评测Controller
 * 
 * @author gjp
 * @date 2023-10-24
 */
@Controller
@RequestMapping("/otc/topic")
public class TopicController extends BaseController
{
    private String prefix = "otc/topic";

    @Autowired
    private ITopicService topicService;

    @RequiresPermissions("otc:topic:view")
    @GetMapping()
    public String topic()
    {
        return prefix + "/topic";
    }

    /**
     * 查询评测列表
     */
    @RequiresPermissions("otc:topic:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Topic topic)
    {
        startPage();
        List<Topic> list = topicService.selectTopicList(topic);
        return getDataTable(list);
    }

    /**
     * 导出评测列表
     */
    @RequiresPermissions("otc:topic:export")
    @Log(title = "评测", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Topic topic)
    {
        List<Topic> list = topicService.selectTopicList(topic);
        ExcelUtil<Topic> util = new ExcelUtil<Topic>(Topic.class);
        return util.exportExcel(list, "评测数据");
    }

    /**
     * 新增评测
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存评测
     */
    @RequiresPermissions("otc:topic:add")
    @Log(title = "评测", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Topic topic)
    {
        return toAjax(topicService.insertTopic(topic));
    }

    /**
     * 修改评测
     */
    @RequiresPermissions("otc:topic:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Topic topic = topicService.selectTopicById(id);
        mmap.put("topic", topic);
        return prefix + "/edit";
    }

    /**
     * 修改保存评测
     */
    @RequiresPermissions("otc:topic:edit")
    @Log(title = "评测", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Topic topic)
    {
        return toAjax(topicService.updateTopic(topic));
    }

    /**
     * 删除评测
     */
    @RequiresPermissions("otc:topic:remove")
    @Log(title = "评测", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(topicService.deleteTopicByIds(ids));
    }
}
